﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YoutubeAccess;
using DataAccess;
using System.Configuration;
using BusinessLogic;
using BusinessLogic.Data;

namespace JobServerConsoleHost
{
    class PollServerForNewWebinarsJob : IJob
    {
        public void DoAction()
        {
            DateTime now = DateTime.Now;
            Webinar[] res =  new GoogleHelper().SearchWebinarSite(getLastPollingTime());
            if (res.Length > 0)
            {
                new BLHelper().AddWebinars(ConfigurationManager.AppSettings["youtubeSite"], now, res);
            }
        }

        private DateTime? getLastPollingTime()
        {
            return DbHelper.Instance.GetLastPollingTime(null, ConfigurationManager.AppSettings["youtubeSite"]); 
        }
    }
}
